"""
节点提交函数，用于提交任务到Deadline

设计：
    将当前文件保存到

"""
import os
import hou
import time
import socket
from cgai_io import copyfile
try:
    import pathlib
    import getpass
    import Deadline.DeadlineConnect as Connect
    url = hou.getenv('DEADLINE_URL')
    port = int(hou.getenv('DEADLINE_PORT'))
    connectionObject = Connect.DeadlineCon(url,port)
except Exception as err:
    pass

i_list = ['FX_mantra_','arnold']
# render_node_list = ['fx_abc', 'FX_rop_geometry_']
render_node_list = ['rop_alembic', 'rop_fbx','rop_gltf','rop_geometry','ifd','arnold']
# work_nodes = ['FX_mantra_', 'fx_abc', 'FX_rop_geometry_','arnold']
work_nodes = ['filecache::2.0','mz_recache','mz_DopImport', 'rop_alembic', 'rop_fbx','rop_gltf','rop_geometry','ifd','arnold']




def B2K(_bytes):
    """
    字节数转KB
    :param _bytes:
    :return:
    """
    return int(_bytes) / 1024

def B2M(_bytes):
    """
    字节大小转M
    :param _bytes:
    :return:
    """
    return int(_bytes) / 1024 / 1024

def B2G(_bytes):
    """
    字节大小转G
    :param _bytes:
    :return:
    """
    return int(_bytes) / 1024 / 1024 / 1024

def B2T(_bytes):
    """
    字节大小转T
    :param _bytes:
    :return:
    """
    return int(_bytes) / 1024 / 1024 / 1024 / 1024


def getDiskFreeSpace(disk_name,bytes_type='B'):
    """
    查询指定磁盘的剩余空间
    :param disk_name:
    :param bytes_type: 'B' 返回原字节大小数,；'K'返回KB大小;'M'返回M大小;'T';返回T大小.
    :return:
    """

    cmd = '''wmic LogicalDisk where "Caption='{}:'" get FreeSpace /value'''.format(disk_name)

    result = os.popen(cmd)
    text = result.read()
    try:
        size = text.strip('\n').split('=')[1]
        # return B2G(size)
        if bytes_type == 'B':
            return int(size)
        elif bytes_type == 'K':
            return B2K(size)
        elif bytes_type == 'M':
            return B2M(size)
        elif bytes_type == 'G':
            return B2G(size)
        elif bytes_type == 'T':
            return B2T(size)

    except Exception as getDiskFreeSpace_ERR:
        print('None',getDiskFreeSpace_ERR)
        return None

# 节点检测
def checkNodes():
    right_nodes = []
    wrong_nodes = []
    
    num = hou.parm('num').evalAsInt()
    if num:
        for n in range(num):
            node_path = hou.parm('node{}'.format(n + 1)).evalAsString()
            if node_path:
                node = hou.node(node_path)
                if node.type().name() not in work_nodes:
                    wrong_nodes.append(node_path)
                else:
                    right_nodes.append(node)

    if wrong_nodes:
        wrong_message = '\n'.join(wrong_nodes)
        right_nodes = False
        hou.ui.displayMessage('错误的节点类型:\n' + wrong_message)

    if right_nodes and not wrong_nodes:
        return True 
    else:
        return False


# GO 顺序解算
def createRenderScript(args):
    direct_render, interval_time, current_node_path, next_node_path = args
    script = """import MZ_tool as mz\nmz.interval_render({},{},'{}','{}')""".format(direct_render, interval_time,
                                                                                    current_node_path, next_node_path)
    return script


def Go(*args):
    check = checkNodes('Render')
    if not check:
        return
    cn = hou.pwd()
    num = cn.parm('num').evalAsInt()

    # 获取节点
    node_list = []
    if num:
        for i in range(num):
            node_path = hou.parm('node{}'.format(i + 1)).eval()
            if node_path:
                node = hou.node(node_path)
                name = node.type().name()
                if name in i_list or name in render_node_list:
                    node_list.append(node)
                    node.parm('postrender').set('')
                    node.parm('lpostrender').set('python')

    if node_list:
        node_script_args_list = []
        interval_time = hou.parm('itime').evalAsInt()
        for i in range(len(node_list)):
            node = node_list[i]
            node_path = node.path()
            direct_render = 1
            if node.type().name() in render_node_list:
                direct_render = 0
            node_args = [direct_render, interval_time, node_path]
            node_script_args_list.append(node_args)
        for s in range(len(node_list)):
            node = node_list[s]

            if s + 1 < len(node_list):
                a_s = node_script_args_list[s]
                next_node_path = node_list[s + 1].path()
                a_s.append(next_node_path)
                script = createRenderScript(a_s)
                node.parm('postrender').set(script)
                node.parm('lpostrender').set('python')

        first_node = node_list[0]
        first_node_direct = node_script_args_list[0][0]
        # print('first_node_direct:',first_node_direct)
        if first_node_direct:
            # print(first_node)
            first_node.render()
        else:
            # print(first_node)
            first_node.node('render').render()








# 设置解算优先级

def setSim(*args):
    num = hou.parm('job').evalAsInt()
    if num:
        for i in range(num):
            sim = hou.parm('sim{}'.format(i + 1)).evalAsInt()
            if sim:
                hou.parm('chunk{}'.format(i + 1)).set(99999)
                hou.parm('priority{}'.format(i + 1)).set(90)
            else:
                priority = hou.parm('priority{}'.format(i + 1)).evalAsInt()
                if priority > 50:
                    hou.parm('chunk{}'.format(i + 1)).set(10)
                    hou.parm('priority{}'.format(i + 1)).set(50)


class DeadlineTool(object):

    def __init__(self):
        super(DeadlineTool, self).__init__()
        self.origin_node_outputpath = {}
        self.concurrent_filter = ['FX_mantra_','arnold']  # 用来添加多开渲染机器

    # def add_deadline_outpath(self, export_type, node_path, raw_outputpath, date_time, var):
    #     """
    #     将输出路径转成deadline的输出路径
    #     """
    #     if raw_outputpath:
    #         job_temp = '$JOB/img' if export_type == 'img' else '$JOB/geo'
    #         if node_path not in self.origin_node_outputpath.keys():  # 当不存在在原始节点时，存入原始节点输出路径
    #             self.origin_node_outputpath[node_path] = raw_outputpath
    #             outputpath = raw_outputpath.replace(job_temp, '`@job`/{}'.format(export_type))
    #         else:
    #             outputpath = self.origin_node_outputpath[node_path].replace(job_temp, '`@job`/{}'.format(export_type))

    #     return outputpath  # .replace('\\','/')

        self.ip = self.get_ip()
        self.hip = hou.getenv('HIP')

    def get_ip(self):
        s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
        s.connect(("8.8.8.8",80))
        a = s.getsockname()
            
        return a[0]

    def replace_hip(self,rawPath):

        if 'CGAI' in self.hip:
            split_path = self.hip.split('CGAI')
            net_cgai = f"//{self.ip}/cgai{split_path[-1]}"
            rawPath = rawPath.replace('$HIP',net_cgai)
        else:
            print('注意:hip文件路径不包含CGAI,渲染输出路径可能会出现在deadline目录下')
        return rawPath

    def replace2cgai_path(self,path):

        if 'CGAI' in path:
            split_path = path.split('CGAI')
            path = f"//{self.ip}/cgai{split_path[-1]}"
        return path

    def change_cpath(self,node):
        """
        将输出路径转成deadline的输出路径
        """
        if node.type().name() == 'rop_comp':
            outputpath = node.parm('coppath').rawValue()
            # node.parm('coppath').set(outputpath.replace("$HIP/","`@cpath`/"))
            node.parm('coppath').set(self.replace_hip(outputpath))
        elif node.type().name() == 'rop_alembic':
            outputpath = node.parm('filename').rawValue()
            # node.parm('filename').set(outputpath.replace("$HIP/","`@cpath`/"))
            node.parm('filename').set(self.replace_hip(outputpath))
        elif node.type().name() == 'rop_geometry':
            outputpath = node.parm('sopoutput').rawValue()
            # node.parm('sopoutput').set(outputpath.replace("$HIP/","`@cpath`/"))
            node.parm('sopoutput').set(self.replace_hip(outputpath))
        elif node.type().name() == 'rop_fbx':
            outputpath = node.parm('sopoutput').rawValue()
            # node.parm('sopoutput').set(outputpath.replace("$HIP/","`@cpath`/"))
            node.parm('sopoutput').set(self.replace_hip(outputpath))
        elif node.type().name() == 'rop_gltf':
            outputpath = node.parm('file').rawValue()
            # node.parm('file').set(outputpath.replace("$HIP/","`@cpath`/"))
            node.parm('file').set(self.replace_hip(outputpath))
        elif node.type().name() == 'FX_mantra_':
            outputpath = node.parm('vm_picture').rawValue()
            # node.parm('vm_picture').set(outputpath.replace("$HIP/","`@cpath`/"))
            node.parm('vm_picture').set(self.replace_hip(outputpath))
        elif node.type().name() == 'ifd':
            outputpath = node.parm('vm_picture').rawValue()
            # node.parm('vm_picture').set(outputpath.replace("$HIP/","`@cpath`/"))
            node.parm('vm_picture').set(self.replace_hip(outputpath))
        elif node.type().name() == 'filecache':
            outputpath = node.parm('file').rawValue()
            # node.parm('file').set(outputpath.replace("$HIP/","`@cpath`/"))
            node.parm('file').set(self.replace_hip(outputpath))
        elif node.type().name() == 'filecache::2.0':
            outputpath = node.parm('basedir').rawValue()
            # node.parm('file').set(outputpath.replace("$HIP/","`@cpath`/"))
            node.parm('basedir').set(self.replace_hip(outputpath))
        elif node.type().name() == 'FX_rop_geometry_':
            outputpath = node.parm('sopoutput').rawValue()
            # node.parm('sopoutput').set(outputpath.replace("$HIP/","`@cpath`/"))
            node.parm('sopoutput').set(self.replace_hip(outputpath))
        elif node.type().name() == 'mz_recache':
            outputpath = node.parm('file').rawValue()
            # node.parm('file').set(outputpath.replace("$HIP/","`@cpath`/"))
            node.parm('file').set(self.replace_hip(outputpath))
        elif node.type().name() == 'mz_DopImport':
            outputpath = node.parm('file').rawValue()
            # node.parm('file').set(outputpath.replace("$HIP/","`@cpath`/"))
            node.parm('file').set(self.replace_hip(outputpath))


    def set_deadline_outputpath(self, node, date_time, var):
        """
        将输出路径转成deadline的输出路径
        """
        if node.type().name() == 'rop_comp':
            outputpath = node.parm('coppath').rawValue()
            node.parm('coppath').set(self.add_deadline_outpath('img', node.path(), outputpath, date_time, var))
        elif node.type().name() == 'rop_alembic':
            outputpath = node.parm('filename').rawValue()
            node.parm('filename').set(self.add_deadline_outpath('geo', node.path(), outputpath, date_time, var))
        elif node.type().name() == 'rop_geometry':
            outputpath = node.parm('sopoutput').rawValue()
            node.parm('sopoutput').set(self.add_deadline_outpath('geo', node.path(), outputpath, date_time, var))
        elif node.type().name() == 'rop_fbx':
            outputpath = node.parm('sopoutput').rawValue()
            node.parm('sopoutput').set(self.add_deadline_outpath('fbx', node.path(), outputpath, date_time, var))
        elif node.type().name() == 'rop_gltf':
            outputpath = node.parm('file').rawValue()
            node.parm('file').set(self.add_deadline_outpath('gltf', node.path(), outputpath, date_time, var))
        elif node.type().name() == 'FX_mantra_':
            outputpath = node.parm('vm_picture').rawValue()
            node.parm('vm_picture').set(self.add_deadline_outpath('img', node.path(), outputpath, date_time, var))
        elif node.type().name() == 'ifd':
            outputpath = node.parm('vm_picture').rawValue()
            node.parm('vm_picture').set(self.add_deadline_outpath('img', node.path(), outputpath, date_time, var))
        elif node.type().name() == 'filecache':
            outputpath = node.parm('file').rawValue()
            node.parm('file').set(self.add_deadline_outpath('geo', node.path(), outputpath, date_time, var))
        elif node.type().name() == 'filecache::2.0':
            outputpath = node.parm('file').rawValue()
            node.parm('file').set(self.add_deadline_outpath('geo', node.path(), outputpath, date_time, var))
        elif node.type().name() == 'FX_rop_geometry_':
            outputpath = node.parm('sopoutput').rawValue()
            node.parm('sopoutput').set(self.add_deadline_outpath('geo', node.path(), outputpath, date_time, var))
        elif node.type().name() == 'mz_recache':
            outputpath = node.parm('file').rawValue()
            node.parm('file').set(self.add_deadline_outpath('geo', node.path(), outputpath, date_time, var))
        elif node.type().name() == 'mz_DopImport':
            outputpath = node.parm('file').rawValue()
            node.parm('file').set(self.add_deadline_outpath('geo', node.path(), outputpath, date_time, var))

    def init_var(self):
        var = hou.contextOption('wedge')
        if var and int(float(var)) >= 0:
            pass
        else:
            hou.setContextOption('wedge', -1)



    # 用这个
    # def submitDeadlineOrder(self, submit_time, var, deadline_hip_path):
    def submitDeadlineOrder(self, deadline_hip_path):
        """
        排序提交
        """

        file_path = deadline_hip_path
        cgai_net_path = self.replace2cgai_path(deadline_hip_path)
        version = hou.applicationVersionString()
        version = '.'.join(version.split('.')[:-1])
        hip_name = os.path.splitext(os.path.split(file_path)[1])[0]
        user_name = getpass.getuser()

        cn = hou.pwd()
        num = cn.parm('num').evalAsInt()

        # 获取该次提交的所有待提交任务内容，通过order作为key
        all_jobs = {}  # {1:[job_data1,job_data2],2:[...],...}

        if num:
            for i in range(num):
                node_path = hou.parm('node{}'.format(i + 1)).eval()
                node = hou.node(node_path) if node_path else None
                if not node:  # 当为空节点时
                    pass
                else:
                    node_name = node.name()
                    f1 = node.parm('f1').evalAsString()
                    f2 = node.parm('f2').evalAsString()
                    order = hou.parm('order{}'.format(i + 1)).evalAsInt()
                    pool = hou.parm('pool{}'.format(i + 1)).evalAsString()
                    chunk = hou.parm('chunk{}'.format(i + 1)).evalAsInt()
                    sim = hou.parm('sim{}'.format(i + 1)).evalAsInt()
                    pri = hou.parm('priority{}'.format(i + 1)).evalAsInt()
                    # concurrentTasks = hou.parm('concurrentTasks{}'.format(i + 1)).evalAsInt()

                    if pri > 50 and not sim:
                        pri = 50

                    # 转deadline输出路径
                    # self.set_deadline_outputpath(node, submit_time, var)
                    self.change_cpath(node)
                    # 计算job
                    props = {}
                    props['Name'] = user_name + '_' + hip_name + '_' + node_name
                    props['UserName'] = user_name
                    props['Frames'] = '{}-{}'.format(f1, f2)
                    props['Plugin'] = 'Houdini'
                    props['Pool'] = pool
                    props['Priority'] = pri
                    props['ChunkSize'] = chunk
                    # if node.type().name() in self.concurrent_filter:
                    if sim: # by is simlation
                        props['ConcurrentTasks'] = 1
                        props['Priority'] = 100
                    # 插件信息
                    plug = {"OutputDriver": node_path,
                            "SceneFile": cgai_net_path,
                            "Version": version
                            }

                    # OutputDriver验证修改
                    if node.type().name() not in render_node_list:  # 带层级的
                        plug["OutputDriver"] = plug["OutputDriver"] + '/render'

                    job_data = {}
                    job_data['props'] = props
                    job_data['plug'] = plug

                    if order not in all_jobs.keys():
                        all_jobs[order] = [job_data]
                    else:
                        all_jobs[order].append(job_data)

        # 提交job
        if all_jobs:
            order_list = sorted(all_jobs.keys())
            pre_id_list = []
            for o in order_list:
                job_list = all_jobs[o]
                order_id_list = []  # 该次order提交后的job id列表
                for data in job_list:
                    if pre_id_list:  # 当存在每order的提交id时,增加依赖
                        data['props']['JobDependencies'] = ','.join(pre_id_list)
                        # 提交job
                        job = connectionObject.Jobs.SubmitJob(data['props'], data['plug'])
                        job_id = job['_id']
                        order_id_list.append(job_id)
                    else:  # 当不存在预先的id列表时,即排序第一的任务，直接提交
                        # print('传输的数据:',data)
                        job = connectionObject.Jobs.SubmitJob(data['props'], data['plug'])
                        # print('返回的job:',job)
                        job_id = job['_id']
                        order_id_list.append(job_id)

                pre_id_list = order_id_list  # 清掉预先的id，替换为当前order提交后的所有job id列表
            print('提交成功')

    def before_scene_saved(self, new_fp):
        """
        不需要了，默认脚本job已经预置了。
        """
        dir_path = os.path.dirname(new_fp)
        if dir_path.endswith('deadline'):
            job_path = os.path.dirname(os.path.dirname(dir_path)).replace('\\', '/')
            hou.setContextOption('job', job_path)
        else:
            job_path = os.path.dirname(dir_path).replace('\\', '/')
            hou.setContextOption('job', job_path)

    # 不使用
    def submit_Deadline(self, submit_time, var, deadline_hip_path):
        """
        只有前一个提交了之后才会有job id
        """

        try:
            import DeadlineConnect as Connect
        except Exception as DeadlineConnect_ERR:
            print('DeadlineConnect_ERR:', str(DeadlineConnect_ERR))
            return
        if not deadline:
            return
        connectionObject = Connect.DeadlineCon(deadline['web_serive'], deadline['port'])
        file_path = deadline_hip_path  # hou.hipFile.name()
        version = hou.applicationVersionString()
        hip_name = os.path.splitext(os.path.split(file_path)[1])[0]
        user_name = getpass.getuser()

        cn = hou.pwd()
        num = cn.parm('gjob').evalAsInt()

        pre_job_id = ''
        if num:
            for i in range(num):
                gnode_path = hou.parm('gnode{}'.format(i + 1)).eval()
                gnode = hou.node(gnode_path) if gnode_path else None
                if not gnode:  # 当为空节点时
                    pass
                else:

                    gnode_name = gnode.name()
                    f1 = gnode.parm('f1').evalAsString()
                    f2 = gnode.parm('f2').evalAsString()
                    gpool = hou.parm('gpool{}'.format(i + 1)).evalAsString()
                    gchunk = hou.parm('gchunk{}'.format(i + 1)).evalAsInt()
                    # gsim = hou.parm('gsim{}'.format(i + 1)).evalAsInt()  # group暂时不用，没有添加gim
                    gpri = hou.parm('gpriority{}'.format(i + 1)).evalAsInt()
                    childnum = hou.parm('child{}'.format(i + 1)).evalAsInt()
                    # gconcurrentTasks = hou.parm('gconcurrentTasks{}'.format(i + 1)).evalAsInt()
                    # 转deadline输出路径
                    self.set_deadline_outputpath(gnode, submit_time, var)

                    # 计算job
                    gprops = {}
                    gprops['Name'] = hip_name + '_' + gnode_name
                    gprops['UserName'] = user_name
                    gprops['Frames'] = '{}-{}'.format(f1, f2)
                    gprops['Plugin'] = 'Houdini'
                    gprops['Pool'] = gpool
                    gprops['Priority'] = gpri
                    gprops['ChunkSize'] = gchunk


                    # 插件信息
                    gplug = {"OutputDriver": gnode_path,
                             "SceneFile": deadline_hip_path,
                             "Version": version
                             }

                    # OutputDriver验证修改
                    if gnode.type().name() in render_node_list:
                        gplug["OutputDriver"] = gplug["OutputDriver"] + '/render'

                    # 提交job
                    gjob = connectionObject.Jobs.SubmitJob(gprops, gplug)
                    print('提交:', gjob)
                    pre_job_id = gjob['_id']

                    # 当存在关联子节点时,排序子节点任务
                    if childnum:
                        for c in range(childnum):
                            gcnode_path = hou.parm('gcnode{}_{}'.format(i + 1, c + 1)).eval()
                            gcnode = hou.node(gcnode_path) if gcnode_path else None
                            if not gcnode:  # 当为空子节点时
                                pass
                            else:
                                gcnode_name = gcnode.name()
                                gcf1 = gcnode.parm('f1').evalAsString()
                                gcf2 = gcnode.parm('f2').evalAsString()
                                gcpool = hou.parm('gcpool{}_{}'.format(i + 1, c + 1)).evalAsString()
                                gcchunk = hou.parm('gcchunk{}_{}'.format(i + 1, c + 1)).evalAsInt()
                                gcpri = hou.parm('gcpriority{}_{}'.format(i + 1, c + 1)).evalAsInt()
                                gcconcurrentTasks = hou.parm('gcconcurrentTasks{}'.format(i + 1)).evalAsInt()
                                # 转deadline输出路径
                                self.set_deadline_outputpath(gcnode, submit_time, var)

                                # 计算子节点job
                                gcprops = {}
                                gcprops['Name'] = hip_name + '_' + gcnode_name
                                gcprops['UserName'] = user_name
                                gcprops['Frames'] = '{}-{}'.format(gcf1, gcf2)
                                gcprops['Plugin'] = 'Houdini'
                                gcprops['Pool'] = gcpool
                                gcprops['Priority'] = gcpri
                                gcprops['ChunkSize'] = gcchunk
                                # if gcnode.type().name() in self.concurrent_filter:
                                #     gcprops['ConcurrentTasks'] = gcconcurrentTasks

                                # 插件信息
                                gcplug = {"OutputDriver": gcnode_path,
                                          "SceneFile": deadline_hip_path,
                                          "Version": version
                                          }

                                # OutputDriver验证修改
                                if gcnode.type().name() in render_node_list:
                                    gcplug["OutputDriver"] = gcplug["OutputDriver"] + '/render'

                                    # 生成子节点job
                                if not pre_job_id:
                                    gcjob = connectionObject.Jobs.SubmitJob(gcprops, gcplug)
                                    pre_job_id = gcjob['_id']
                                else:  # 添加依赖
                                    gcprops['JobDependencies'] = pre_job_id
                                    gcjob = connectionObject.Jobs.SubmitJob(gcprops, gcplug)
                                    pre_job_id = gcjob['_id']

                                print('\n')
                                print('子job属性:', gcprops)
                                print('\n')
                                print('gcjob:', gcjob)

                    pre_job_id = ''  # 一个组完成后，清空pre_job_id

        # hou.ui.displayMessage('提交成功')

    def Deadline(self):
        # 会默认保存
        # result = hou.ui.displayMessage('请确认已保存工程!!', title='工程确认', buttons=('提交', 'Save and Submit', 'Cancel'),
        #                                default_choice=0)

        # job_path = hou.contextOption('job')
        # if job_path:
        #     hou.putenv('JOB', job_path)

        # self.init_var()
        hip_path_list = []
        fn = hou.hipFile.name()
        bn = hou.hipFile.basename()
        # hou.setContextOption('cpath', os.path.dirname(fn).replace('\\', '/'))  # 本地无感渲染现在不需要了
        pp = pathlib.Path(fn)
        dirname = pp.parent
        deadline = pathlib.Path(dirname, 'deadline')
        if not os.path.exists(deadline):
            os.makedirs(deadline)

        tar = pathlib.Path(deadline, bn)
        # var_min = var_max = 0  # 暂时不添加wedge
        # if hou.parm('wa').evalAsInt():
        #     var_min = hou.parm('varx').evalAsInt()
        #     var_max = hou.parm('vary').evalAsInt()
        submit_time = time.strftime('%Y-%m-%d__%H-%M-%S')
        # for i in range(var_min, var_max + 1):
        stem = tar.stem
        # print(stem)  #cnn
        suf = tar.suffix
        # print(suf)   #.py
        # deadline_hip = '{}_wedge{}_{}{}'.format(stem, i, submit_time, suf)
        deadline_hip = '{}_{}{}'.format(stem, submit_time, suf)
        new_fp = str(pathlib.Path(deadline, deadline_hip)).replace('\\', '/')  # 获取提供deadline的hip文件路径
        # print(new_fp)
        # hou.setContextOption('wedge', i)
        hip_path_list.append(new_fp)
        hou.hipFile.save()  # 原地保存

        copyfile(fn,new_fp,wait=True)
        self.submitDeadlineOrder(new_fp)


        # freespace = self._getFreeSpace(deadline)
        # if freespace:
        #     result = '提交成功,\n 剩余空间{}T'.format(round(freespace, 2)) #if freespace else '提交成功\n请映射{}盘符'.format(cfg.DISK)
        #     hou.ui.displayMessage(result)


    def _getFreeSpace(self,path):
        disk = str(path).split(':')[0]
        freespace = getDiskFreeSpace(disk, 'T')
        return freespace




def submit_deadline_order(*args):
    check = checkNodes()
    if not check:
        return
    dt = DeadlineTool()
    dt.Deadline()    